#include "QueueBullet.h"


CQueueBullet::CQueueBullet()
{
	head_ = tail_ = NULL;
}


CQueueBullet::CQueueBullet(TypeOfBullet type)
{
	int i;

	switch (type)
	{
	case NORMAL_BULLET:
		for (i = 0; i < 4; i++)
		{
			CNodeBullet* p = new CNodeBullet(NORMAL_BULLET);
			Insert(p);
		}
		break;
	case M_BULLET:
		for (i = 0; i < 4; i++)
		{
			CNodeBullet* p = new CNodeBullet(M_BULLET);
			Insert(p);
		}
		break;
	case F_BULLET:
		for (i = 0; i < 4; i++)
		{
			CNodeBullet* p = new CNodeBullet(F_BULLET);
			Insert(p);
		}
		break;
	case S_BULLET:
		for (i = 0; i < 4; i++)
		{
			CNodeBullet* p = new CNodeBullet(S_BULLET);
			Insert(p);
		}
		break;
	case L_BULLET:
		for (i = 0; i < 4; i++)
		{
			CNodeBullet* p = new CNodeBullet(L_BULLET);
			Insert(p);
		}
		break;
	}
}


CQueueBullet::~CQueueBullet()
{
	CNodeBullet* p = head_;
	while (p != NULL)
	{
		head_ = head_->next_;
		p->next_ = NULL;
		delete p;
		p = head_;
	}
}


int CQueueBullet::Empty()
{
	if (head_ == NULL)
		return 1;
	else
		return 0;
}


void CQueueBullet::Insert(CNodeBullet* item)
{
	if (head_ == NULL)
	{
		head_ = item;
		tail_ = item;
	}
	else
	{
		tail_->next_ = item;
		tail_ = item;
	}
}


CNodeBullet* CQueueBullet::Remove()
{
	if (Empty())
		return NULL;
	else
	{
		CNodeBullet* item = head_;
		head_ = head_->next_;
		item->next_ = NULL;
		if (head_ == NULL)
			tail_ = NULL;
		item->timeBeginShoot = GetTickCount();
		return item;
	}
}